import { createSlice, configureStore } from "@reduxjs/toolkit";
// redux组成
// 1. state
// 2. action 触发动作
// 3. reducer 执行触发动作改变状态
// 4. dispatch 分发动作
const slice = createSlice({
    name: "app",
    initialState: {
        count: 0,
    },
    reducers: {
        add(state) {
            state.count = state.count + 1;
        },
        cut(state) {
            state.count = state.count - 1;
        },
    },
});
const store = configureStore({
    reducer: slice.reducer,
});
const { add, cut } = slice.actions;

store.subscribe(() => {
    console.log("监听触发了");
    console.log(store.getState()); // 获取最新状态
});
// 第一种用导出的函数触发
store.dispatch(add(10)); // 动作分发
// 第二种用对象形式触发
store.dispatch({ type: "app/add" });
store.dispatch(cut()); // 动作分发

function App(params) {
    return <div>App</div>;
}
export default App;
